<template>
	<view class="u-m-40 u-m-t-50">
		<view class="u-font-38 u-m-b-35" style="font-weight: bold;">{{ detail.noticeTitle }}</view>
		<view class="u-font-14 u-m-b-35" style="color: #777;">{{ detail.createTime }} {{ detail.noticeType == 1 ? '通知' : '公告' }}</view>
		<view>{{ detail.noticeContent }}</view>
		<view style="position: fixed;bottom: 0;left: 0;right: 0;height: 63px;">
			<u-button :type="detail.isCollected == '已收藏' ? 'primary' : 'info'" size="large" :text="detail.isCollected || '加入收藏'" @click="collectChange(detail)"></u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 0,
				detail: {
					noticeId: null,
					createTime: "",
					creatorName: "",
					noticeContent: "",
					noticeTitle: "",
					noticeType: null,
					status: null,
					isCollected: null
				},
				
				isCollect: false,
			}
		},
		methods: {
			getDetail(id) {
				this.$api.getInfoNotices(id).then(res => {
					let d = res.data
					this.detail = d
				})
			},
			addBrowhis(id) {
				this.$api.addBrowhis({
					dataId: id,
				})
			},
			collectChange(record) {
				if (record.isCollected == '已收藏') {
					this.$api.delCollect({
						ids: record.noticeId,
					}).then(res => {
						this.$refs.uToast.show({
							message: '操作成功',
							type: 'success',
							duration: 1500,
							complete: () => {
								if (this.type == 1) {
									this.$fallback(1, {
										key: 'reset',
										back: true
									})
								}
								this.getDetail(record.noticeId)
							}
						});
						
					})
				} else {
					this.$api.addCollect({
						dataId: record.noticeId,
					}).then(res => {
						this.$refs.uToast.show({
							message: '操作成功',
							type: 'success',
							duration: 1500,
							complete: () => {
								this.getDetail(record.noticeId)
							}
						});
					})
				}
				
			}
		},
		onLoad() {
			const {
				id, type
			} = this.$Route.query;
			this.type = type;
			this.getDetail(id);
			this.addBrowhis(id);
		},
	}
</script>

<style>
</style>